package org.example.projectdemo.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDate;
import java.time.LocalTime;

@Getter
@Setter
@Entity// 标记这是一个JPA实体
@Table(name = "attendance", schema = "projectfrist")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Attendance {
    @Id// 标记为主键
    @GeneratedValue(strategy = GenerationType.IDENTITY)// 主键自增策略
    @Column(name = "id", nullable = false)
    private Long id;// 对应数据库 bigint

    // 关联学生：多个考勤记录属于一个学生
    @NotNull(message = "学生信息不能为空")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "student_id", nullable = false) // 指定外键列名
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    private Student student;

    // 关联排课：多个考勤记录属于一次排课
    @NotNull(message = "排课信息不能为空")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "schedule_id", nullable = false) // 指定外键列名
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    private Schedule schedule;

    @NotNull(message = "考勤日期不能为空")
    @Column(name = "attendance_date", nullable = false)
    private LocalDate attendanceDate;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private AttendanceStatus status = AttendanceStatus.ABSENT;

    @Column(name = "check_in_time")
    private LocalTime checkInTime;

    @Column(name = "remark", length = 500)
    private String remark;

    // 考勤状态枚举
    public enum AttendanceStatus {
        PRESENT,    // 出席
        ABSENT,     // 缺席
        LATE,       // 迟到
        EXCUSED     // 请假
    }

}